package com.zhao.dota.task;

import cn.hutool.core.bean.BeanUtil;
import com.zhao.dota.common.task.BaseTask;
import com.zhao.dota.model.Item;
import com.zhao.dota.processor.ItemProcessor;
import com.zhao.dota.service.ItemService;
import com.zhao.dota.struct.SteamResult;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class UpdateItemTask extends BaseTask {

    @Resource
    private ItemService itemService;
    @Resource
    private ItemProcessor itemProcessor;

    @Override
    protected void execute() {
        SteamResult<ItemProcessor.Container> itemList = itemProcessor.getItemList();
        List<Item> heroes = itemList.getResult().getItems().stream().map(h -> {
            Item item = new Item();
            BeanUtil.copyProperties(h, item);
            return item;
        }).collect(Collectors.toList());
        itemService.updateList(heroes);
    }

    @Override
    protected String getKey() {
        return "itemTask";
    }
}
